#include "klistwidget.h"
#include "accessinfohelper.h"
#include <QDebug>
namespace kdk
{

class KListWidgetPrivate : public QObject
{
    Q_OBJECT
    Q_DECLARE_PUBLIC(KListWidget)
public:
    KListWidgetPrivate(KListWidget* parent);
private:
    KListWidget* q_ptr;
    QListWidgetItem* item;
    QListWidgetItem * m_item;

};

KListWidgetPrivate::KListWidgetPrivate(KListWidget* parent):q_ptr(parent)
{
    Q_Q(KListWidget);
    setParent(parent);
}
KListWidget::KListWidget(QWidget* parent):d_ptr(new KListWidgetPrivate(this))
{
    Q_D(KListWidget);
}
void KListWidget::AddItemWidget(KItemWidget *m_itemwidget)
{
    Q_D(KListWidget);
    if(!m_itemwidget)
        return ;
    d->item = new QListWidgetItem(this);
    d->item->setSizeHint(QSize(this->width(),54));


    this->setItemWidget(d->item,m_itemwidget);

    //建立连接
    connect(this,&KListWidget::itemClicked,this,[=](QListWidgetItem *current){
        KItemWidget* curWidget = dynamic_cast<KItemWidget*>(this->itemWidget(current));
        if(curWidget)
            curWidget->SetInverse();
    });
    connect(this,&KListWidget::currentItemChanged,this,[=](QListWidgetItem *current, QListWidgetItem *previous){
        KItemWidget* curWidget = dynamic_cast<KItemWidget*>(this->itemWidget(current));
        KItemWidget* preWidget = dynamic_cast<KItemWidget*>(this->itemWidget(previous));
        if(curWidget&&!preWidget)
        {           
            curWidget->CancelInverse();
        }
        else if(curWidget)
        {
             curWidget->SetInverse();
        }
        if(preWidget)
        {
            preWidget->CancelInverse();
        }
    });
}



}
#include "klistwidget.moc"
#include "moc_klistwidget.cpp"
